package com.nf.health.app.intervention_details.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.intervention_details.bean.DoctorOrderDetailsBean;
import com.nf.health.app.utils.TextUtilTools;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by 恩福 on 2016/11/24.
 * 医嘱详情里面的用药处方 Adapter
 *
 * @auther changpeng
 * @email obj_cp@126.com
 */

public class DoctorOrderPrescriptionDrugsAdapter extends RecyclerView.Adapter {
    private List<DoctorOrderDetailsBean.MedicationBean> medication;
    private Context mContext;

    public DoctorOrderPrescriptionDrugsAdapter(Context context, List<DoctorOrderDetailsBean.MedicationBean> medication) {
        this.mContext = context;
        this.medication = medication;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.doctor_order_prescription_drugs, parent, false);
        return new PdHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        PdHolder pdHolder = (PdHolder) holder;
        DoctorOrderDetailsBean.MedicationBean bean = medication.get(position);
        String drugName = "<font color='#FFA500'>药品名称</font> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+bean.getMedicineName()+"";

        String dosage =
                "<font color='#FFA500'>共计</font> <big>"+bean.getTotalDay()+"</big> <font color='#FFA500'>日</font>&nbsp;&nbsp;&nbsp;" +
                "<font color='#FFA500'>每日</font> <big>"+bean.getEveryDayNum()+"</big> <font color='#FFA500'>次</font>&nbsp;&nbsp;&nbsp;" +
                "<font color='#FFA500'>每次</font> <big>"+bean.getOnceNum()+"</big> <font color='#FFA500'>"+bean.getUnit()+"</font>&nbsp;&nbsp;&nbsp;";

        String timeWay =
                "<font color='#FFA500'>服药时间</font> &nbsp;&nbsp;&nbsp;"+bean.getMedicineTime()+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
                "<font color='#FFA500'>用药方法</font> &nbsp;&nbsp;&nbsp;"+bean.getMedicineMethod()+"";
        TextUtilTools.setTextFromHtml(pdHolder.tvDrugName,drugName);
        TextUtilTools.setTextFromHtml(pdHolder.tvDosage,dosage);
        TextUtilTools.setTextFromHtml(pdHolder.tvTimeWay,timeWay);
    }

    @Override
    public int getItemCount() {
        return medication == null ? 0 : medication.size();
    }

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    class PdHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_drug_name)
        TextView tvDrugName;
        @Bind(R.id.tv_dosage)
        TextView tvDosage;
        @Bind(R.id.tv_time_way)
        TextView tvTimeWay;

        public PdHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
